package Wrapper;

import entity.Orders;
import entity.Ticket;
import entity.Train;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

public class OrderWrapper {
    public static ArrayList<Orders> OrderWrapper(ResultSet rs, ArrayList<Orders> ordersList) throws SQLException {
        Orders orders = new Orders();
        Ticket ticket = new Ticket();
        Train train = new Train();
        orders.setOrderId(rs.getInt(1));
        orders.setTrain_id(rs.getInt(2));
        orders.setUserId(rs.getInt(3));
        orders.setTrain_id(rs.getInt(4));
        orders.setTotalPrice(rs.getString(5));
        orders.setOrderTime(rs.getDate(6));
        orders.setStatus(rs.getString(8));
        ticket.setTicketId(rs.getInt(9));
        ticket.setTrainId(rs.getInt(10));
        ticket.setUserId(rs.getInt(11));
        ticket.setSeatType(rs.getString(12));
        ticket.setSeatNumber(rs.getString(13));
        ticket.setPurchaseTime(rs.getDate(14));
        ticket.setStatus(rs.getString(16));
        train.setTrainId(rs.getInt(19));
        train.setTrainName(rs.getString("train_name"));
        train.setDepartureTime(rs.getDate("departure_time"));
        train.setArrivalTime(rs.getDate(22));
        train.setStartStation(rs.getString(23));
        train.setEndStation(rs.getString(24));
        orders.setTicket(ticket);
        orders.setTrain(train);
        ordersList.add(orders);
        return ordersList;
    }
}
